package com.maimao.model.user.sys;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.*;

import javax.annotation.Nullable;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.beans.Transient;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 资源
 * @author MaoLin Wang
 * @date 2020/11/28 11:12 上午
 */
@Setter
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName("sys_resources")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Resources implements Serializable {
    private static final long serialVersionUID = 5988310749126766745L;

    @TableId(type = IdType.AUTO)
    private Integer id;

    @NotBlank(message = "资源名不能为空")
    private String name;

    @NotBlank(message = "编码不能为空")
    private String code;

    private String path;

    @NotNull(message = "请选择父资源")
    @TableField(value = "parent_id")
    private Integer parentId;

    private String icon;

    @TableField(value = "`order`")
    private Integer order;

    @TableField(value = "`status`")
    @TableLogic(value = "1",delval = "0")
    private Integer status;

    @TableField(value = "component")
    private String component;

    @TableField(value = "redirect")
    private String redirect;

    @TableField(value = "side")
    private Boolean side;

    /**
     * 0 左侧导航菜单(无路由)1 菜单 2 按钮 3读写
     */
    @TableField(value = "type")
    private Integer type;

    @TableField(value = "create_user")
    private Integer createUser;

    @TableField(value = "create_time")
    private LocalDateTime createTime;

    @TableField(value = "update_time")
    private LocalDateTime updateTime;

    @TableField(value = "update_user")
    private Integer updateUser;

    @NotNull(message = "请选择是后台还是前端资源")
    @TableField(value = "sys")
    private Boolean sys;


    @TableField(exist = false)
    private List<Resources> children;


    @Override
    public String toString() {
        return "Resources{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", code='" + code + '\'' +
                ", path='" + path + '\'' +
                ", parentId=" + parentId +
                ", icon='" + icon + '\'' +
                ", order=" + order +
                ", status=" + status +
                ", component='" + component + '\'' +
                ", redirect=" + redirect +
                ", side=" + side +
                ", sys=" + sys +
                ", type=" + type +
                ", createUser=" + createUser +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                ", updateUser=" + updateUser +
                '}';
    }
}
